$(function () {
    let query = {
        url: {
            af: 'front/queryAnFangZiZhi',
            xy: 'front/queryXinYongDengJi',
            ry: 'front/queryRenYuan'
        },
        init: function () {
            let _self = query
            // 初始化
            _self.type = getUrlParam('type')
            if (_self.type === 'AnFangZiZhi') {
                _self.curShow = $('#query_af')
                _self.toquery(_self.url.af)
                $('#query_title').html('安防资质查询')
            } else if (_self.type === 'XinYongDengJi') {
                _self.curShow = $('#query_xy')
                _self.toquery(_self.url.xy)
                $('#query_title').html('信用评价查询')
            } else if (_self.type === 'RenYuan') {
                _self.curShow = $('#query_ry')
                _self.toquery(_self.url.ry)
                $('#query_title').html('人员查询')
            }
            _self.curShow.show().siblings().hide()
        },
        toquery: (url) => {

            let _self = query
            let param = {
                nameOrNum: decodeURI(getUrlParam('key')) || ''
            }
            
            $.post(url, param, (data) => {
                if (data.success) {
                    _self.curShow.find('span').each(function() {
                        $(this).html(data[$(this).attr('name')] || '')
                    })
                } else {
                    alert(data.msg)
                }
            })
        }
    }
    query.init()
})